package com.app114.app.android.rk;

import java.util.List;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.app114.app.android.rk.adapter.WebsAdapter;
import com.app114.app.android.rk.bean.WebSiteItem;
import com.app114.app.android.rk.utils.DataFactory;

public class CategoryActivity extends BaseFragmentActivity implements OnItemClickListener {

	private GridView gridView;
	private String title;
	private List<WebSiteItem> mWebSiteItems ;

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Intent intent = new Intent(mContext, Browser.class);
		intent.setAction(Intent.ACTION_VIEW);
		intent.setData(Uri.parse(mWebSiteItems.get(arg2).getGUrl()));
		startActivity(intent);
	}

	@Override
	protected void activitySetup(Bundle savedInstanceState) {
		Intent intent = getIntent();
		if (intent == null || (title = intent.getAction()) == null) {
			return;
		}

		setContentView(R.layout.activity_category_detail);
		getSupportActionBar().setTitle(title);
		gridView = (GridView) findViewById(R.id.gridView);
		gridView.setOnItemClickListener(this);
		mWebSiteItems = DataFactory.getWebSiteList(title) ;
		gridView.setAdapter(new WebsAdapter(mContext, mWebSiteItems));
	}

	@Override
	protected boolean _onCreateOptionsMenu(Menu menu) {
		getSupportMenuInflater().inflate(R.menu.activity_category_detail, menu);
		return true;
	}

	@Override
	protected boolean _onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	protected void activityDestory() {
		// TODO Auto-generated method stub

	}
}
